cmake_minimum_required(VERSION 3.0.2)
project(fanguangbantrilateration)

#启用详细日志可以帮助确定具体的错误来源。【控制台输入以下编译命令】
#catkin_make --cmake-args -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON


set( CMAKE_BUILD_TYPE Release )
#set( CMAKE_BUILD_TYPE Debug )
#if( CMAKE_BUILD_TYPE STREQUAL "Release")
#  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -fPIC")
#else()
#  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -std=c++11 -fPIC")
#endif()

# 设置编译选项支持UTF-8
#add_compile_options(-std=c++11 -finput-charset=UTF-8 -fexec-charset=UTF-8)
#add_compile_options(-std=c++11 )
if( CMAKE_BUILD_TYPE STREQUAL "Release")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++14 -finput-charset=UTF-8 -fexec-charset=UTF-8 -fPIC")
else()
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -std=c++14 -finput-charset=UTF-8 -fexec-charset=UTF-8 -fPIC")
endif()

#在 CMakeLists.txt 中确保启用了调试信息，然后重新编译项目：catkin_make， 使用 GDB 启动你的 ROS 节点： gdb --args /path/to/your/node_executable
# valgrind --tool=memcheck --leak-check=full /path/to/your/node_executable
#set(CMAKE_BUILD_TYPE Debug)
# <!-- <node  pkg="trilateration" type="trilateration_test25_node" name="trilateration_test25_node" output="screen" launch-prefix="gdb -ex run --args"> -->


#if( CMAKE_BUILD_TYPE STREQUAL "Release")
#  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++14  -fPIC")
#else()
#  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -std=c++14  -fPIC")
#endif()

#find_package(Eigen REQUIRED QUIET)
find_package(Eigen3 REQUIRED)
find_package(Ceres REQUIRED QUIET COMPONENTS SuiteSparse)
file(GLOB_RECURSE HEADER_FILES include/*.h)
#邮箱
find_package(CURL REQUIRED)
#find_package(Libsoup-2.4 REQUIRED)
# 设置 CMAKE_PREFIX_PATH
#set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/cmake/Libsoup-2.4")
#find_package(Libsoup-2.4 REQUIRED)
#find_package(SOUP REQUIRED)
#find_package(PCL REQUIRED QUIET)


file(GLOB_RECURSE HEADER_FILES include/*.h)
#GLOB_RECURSE，它会递归地搜索指定文件夹及其子文件夹中匹配指定模式
#file(GLOB_RECURSE SOURCE_FILES src/*.cpp)

#GLOB 只会在指定文件夹中搜索匹配模式的文件，不会递归搜索其子文件夹。
#file(GLOB SOURCE_FILES src/*.cpp)


find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
geometry_msgs
sensor_msgs
tf
#消息
message_filters 
#message_runtime
message_generation
dynamic_reconfigure
#pcl_conversions
#pcl_ros  # sudo apt-get install ros-<distro>-pcl-ros


)

##srv消息
#file(GLOB_RECURSE SERVICE_FILES srv/*.srv)
## 展开文件列表
#foreach(SERVICE_FILE ${SERVICE_FILES})
#  # 提取文件名
#  get_filename_component(SERVICE_NAME ${SERVICE_FILE} NAME_WE)
#  #注意：增加新消息文件后，需要删除原编译产生的cmakeList.txt,否则不编译新加入的消息文件。
#  add_service_files(
#          FILES
#          ${SERVICE_NAME}.srv
#  )
#endforeach()


# 搜索所有的 .srv 文件
#file(GLOB SERVICE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/srv" "srv/*.srv")
## 添加服务文件
#add_service_files(
#        DIRECTORY srv
#        FILES
#        ${SERVICE_FILES}
#
#)

add_service_files(
        DIRECTORY srv
        FILES
        trilateration_srvs.srv
        matchcostmapwithscan_srvs.srv
)


#msg 消息
#file(GLOB MESSAGE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "msg/*.msg)")
#  #注意：增加新消息文件后，需要删除原编译产生的cmakeList.txt,否则不编译新加入的消息文件。
#  add_message_files(
#          DIRECTORY msg
#          FILES
#          ${MESSAGE_FILES}
#  )

add_message_files(
          DIRECTORY msg
          FILES
          trilateration_read_time_log.msg
          matchcostmapwithscan_result.msg
  )


# cfg 消息
#file(GLOB_RECURSE CFG_FILES cfg/*.cfg)
#foreach(CFG_FILE ${CFG_FILES})
#  # 提取文件名
#  get_filename_component(CFG_NAME ${CFG_FILE} NAME_WE)
#  generate_dynamic_reconfigure_options(
#          cfg/${CFG_NAME}.cfg
#  )
#endforeach()


generate_dynamic_reconfigure_options(
        cfg/trilaterationParam.cfg
)


## Generate services in the 'srv' folder
#add_service_files(
#        FILES
#        ## trilateration_srvs.srv
#        ${SERVICE_SRV}
#)

#消息
## Generate added messages and services with any dependencies listed here
generate_messages(
        DEPENDENCIES
        std_msgs  # Or other packages containing msgs
        geometry_msgs
)

catkin_package(
  #INCLUDE_DIRS include
  #LIBRARIES
  CATKIN_DEPENDS message_runtime
  #消息

  
  message_filters
  dynamic_reconfigure
)

#set(lib_files )


include_directories(include

        # 包含 libsoup 的头文件
      # ${LIBSOUP_INCLUDE_DIRS}
        ${catkin_INCLUDE_DIRS}
       # ${PCL_INCLUDE_DIRS}
        ${CERES_INCLUDE_DIRS}
        /usr/include/eigen3
        )

add_subdirectory(src/json)
include_directories(./src/json)

add_subdirectory(src/mutex)
include_directories(./src/mutex)



#----------------------------------------------------
#GLOB 只会在指定文件夹中搜索匹配模式的文件，不会递归搜索其子文件夹。
#file(GLOB SOURCE_FILES src/*.cpp)
#add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES})
#target_link_libraries(${PROJECT_NAME}  ${catkin_LIBRARIES}  fanguangbantrilateration_json_node)

#反光柱定位算法  ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}
add_executable(${PROJECT_NAME}  src/trilateration.cpp)
#优先编译依赖或消息
add_dependencies(${PROJECT_NAME}  ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME}  ${catkin_LIBRARIES} ${CERES_LIBRARIES} fanguangbantrilateration_json_node)





#雷达匹与周边特征的配情况
add_executable(${PROJECT_NAME}_matchCostmapWithScan_node src/matchCostmapWithScan.cpp)
#优先编译依赖或消息
add_dependencies(${PROJECT_NAME}_matchCostmapWithScan_node  ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME}_matchCostmapWithScan_node  ${catkin_LIBRARIES}  )

#控制台输出中文日志
add_executable(${PROJECT_NAME}_read_time_log_node src/trilateration_read_time_log.cpp)
#优先编译依赖或消息
add_dependencies(${PROJECT_NAME}_read_time_log_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME}_read_time_log_node  ${catkin_LIBRARIES}  )





#add_executable(${PROJECT_NAME}_sendRegisterMessageEmailSoup_node src/sendRegisterMessageEmailSoup.cpp)
#target_link_libraries(${PROJECT_NAME}_sendRegisterMessageEmailSoup_node  ${catkin_LIBRARIES}  ${CURL_LIBRARIES}  )

#add_library(fanguangbantrilateration_json_node base64.cpp CSmtp.cpp md5.cpp main.cpp)
#add_executable(${PROJECT_NAME}_sendRegisterMessageEmailCsmtp_ssl_node src/csmtp_ssl/base64.cpp src/csmtp_ssl/CSmtp.cpp  src/csmtp_ssl/md5.cpp  src/csmtp_ssl/main.cpp  )
#target_link_libraries(${PROJECT_NAME}_sendRegisterMessageEmailCsmtp_ssl_node  ${catkin_LIBRARIES}  ${CURL_LIBRARIES}  )
#

#add_library(fanguangbantrilateration_json_node base64.cpp CSmtp.cpp md5.cpp main.cpp)
#add_executable(${PROJECT_NAME}_sendRegisterMessageEmailCsmtp_mail_node src/mail/Base64.h src/mail/mail.cpp src/mail/main.cpp  )
#target_link_libraries(${PROJECT_NAME}_sendRegisterMessageEmailCsmtp_mail_node  ${catkin_LIBRARIES}  ${CURL_LIBRARIES}  )



# install executables and/or libraries
install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_matchCostmapWithScan_node ${PROJECT_NAME}_read_time_log_node 
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)


install(DIRECTORY include/${PROJECT_NAME}/
        DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
        FILES_MATCHING PATTERN "*.h"
        )

install(DIRECTORY launch param rviz
        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
        )

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT header)

# install files
foreach(dir launch)
install(DIRECTORY ${dir}/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/${dir})
endforeach(dir)







